<template>
  <div class="payee-split-info">
    <el-table
      :data="list"
      border
    >
      <el-table-column
        label="款项明细编号"
        prop="splitNumber"
      />
      <el-table-column
        label="款项类型"
        prop="splitType"
      >
        <template #default="scope">
          <span>{{ getLabel( 'payee_type', scope.row.splitType) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="row?.customerType!=='agent'"
        label="款项来源"
        prop="source"
      >
        <template #default="scope">
          <span>{{ getLabel('payee_from', scope.row.source) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="金额（元）"
        prop="splitAmount"
      >
        <template #default="scope">
          <span>{{ moneyFormat(scope.row.splitAmount) }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { inject, reactive, toRefs, watch } from 'vue'

export default {
  props: {
    row: {
      type: Object,
      default: () => {},
    },
    id: {
      type: Number,
      default: () => {},
    },
  },
  setup(props, context) {
    const api = inject('api')
    const datas = reactive({
      count: 0,
      list: [],
    })
    const getList = (id) => {
      var data = {
        receiveMoneyId: id,
        splitTypeFrom: '3',
      }
      api.internalControl
        .INTERNAL_CONTROL_FINANCE_SPLIT_LIST(data)
        .then((res) => {
          if (res.code === 0) {
            datas.list = res.data.list || []
          }
        })
    }

    watch(
      () => props.row,
      (newval, oldval) => {
        if (newval) {
          getList(newval.id)
        }
      },
      { immediate: true, deep: true }
    )
    watch(
      () => props.id,
      (newval, oldval) => {
        if (newval) {
          getList(newval)
        }
      },
      { immediate: true, deep: true }
    )

    return {
      ...toRefs(datas),
    }
  },
}
</script>

<style lang="scss" scoped>
</style>
